<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>打开关闭窗口</title>
	</head>

	<body>
		<br />
		<input type="button" value="打开" onclick="openwin()" />
		<br />
		<br />
		<input type="button" value="关闭" onclick="colsewin()" />
		<br />
		<br />
		<input type="button" value="检测窗口是否关闭" onclick="checkwin()" />
		<script>
			var win=null;

			//打开窗口
			function openwin() {
				win = window.open('', '我的新窗口', 'width=400,height=200,left=200,top=100');
				//在窗口最中写入内容
				win.document.write(win.name + '<br>');
				win.document.write(win.parent);
			}
			//关闭窗口
			function colsewin() {
				//若没有打开，关闭
				//若没有窗口打开，弹出框提示
				if(win != null) {
					win.close();
					win = null;
				} else {
					alert("没有新窗口打开")
				}
			}
		</script>
	</body>

</html>